<template>
  <!--项目计划信息  -->
  <div>
    <FormPanel
      ref="formPanel"
      :list="initForm"
      :cols="2"
      :formType="value.type"
      :labelWidth="140"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { region } from '@/api/cms-common/region';
import { getBigMarketType, getSmallMarketType } from '@/api/cms-api/projectOperating/plan/index';
import { selectListByBill } from '@/api/cms-api/projectOperating/plan/index';
export default {
  mixins: [dictionary, region],
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      initForm: this.initFormFun(),
      formValue: {}
    };
  },
  mounted() {
    console.log(this.value); //获取到行id 、类型（新增、详情）
    //请求接口进行赋值，自己写吧
  },
  methods: {
    init() {
      if (this.value.type === 'show') {
                //查询附件
        this.file();//显示附件
        this.initForm.forEach(x => {
          x.initialValue = this.value.row[x.fieldName];
          if (x.fieldName == 'modelLists') {
            console.log(this.value.row.modelList);
            if (this.value.row.modelList != undefined) {
              let modelName = [];
              for (let i = 0; i < this.value.row.modelList.length; i++) {
                modelName.push(this.value.row.modelList[i].modelName);
              }
              x.initialValue = modelName;
            } else {
              x.initialValue = this.value.row[x.fieldName];
            }
          }
          if (x.fieldName == 'planBoothAmount') {
            if (x.initialValue == null) {
              x.initialValue = '';
            }
          }
          if (x.fieldName == 'planBuildAmount') {
            if (x.initialValue == null) {
              x.initialValue = '';
            }
          }
          if (x.fieldName == 'provinceId') {
            x.initialValue = this.createRegionText(this.value.row.provinceId);
          }
          if (x.fieldName == 'cityId') {
            x.initialValue = this.createRegionText(this.value.row.cityId);
          }
        });
      }
      this.projectMainClass = this.value.row.projectMainClass;
      //初始化项目大类
      this.initBigMarketType();
      //初始化项目小类
      this.initMarketTypeSmall(this.value.row.projectMainClass);
    },
     async file() {
      //报备附件
      this.fileRes = await selectListByBill({ planId: this.value.row.planId, billType: 25791006 });
      if (this.fileRes.data.length > 0) {
        let caseUrlList = [];
        for (let j = 0; j < this.fileRes.data.length; j++) {
          let o1 = { name: this.fileRes.data[j].fileName };
          let o2 = { url: this.fileRes.data[j].fileId };
          let a = Object.assign(o1, o2);
          caseUrlList.push(a);
        }
        this.initForm.find(item => item.fieldName === 'uploadFileList').initialValue = caseUrlList;
      }
    },
    //搜索数据
    initFormFun() {
      return [
         {
          type: 'TEXT_AREA',
          label: '项目名称',
          fieldName: 'projectName',
          initialValue: '',
          disabled: true,
          placeholder: ''
        },
        {
          type: 'TEXT_AREA',
          label: '项目介绍（项目描述）',
          fieldName: 'projectDesc',
          initialValue: '',
          disabled: true,
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: '项目车型',
          fieldName: 'modelLists',
          selfCols:2,
          initialValue: [],
          disabled: true,
          temList: [], //复选框数据源
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: '场地',
          fieldName: 'projectDesc',
          initialValue: '',
          disabled: true,
          placeholder: ''
        },
        {
          type: 'SELECT',
          label: '合作方式',
          fieldName: 'cooperationMethod',
          initialValue: '',
          disabled: true,
          placeholder: '',
          itemList: this.createDictList('2532')
        },
        {
          type: 'INPUT',
          label: '计划开展/投放时间',
          fieldName: 'planLaunchReleaseTime',
          initialValue: '',
          selfCols:2,
          disabled: true
        },
        {
          type: 'DATE',
          label: '开始日期',
          fieldName: 'planStartDate',
          valueFormat: 'yyyy-MM-dd',
          disabled: true,
          initialValue: '',
          placeholder: ''
        },
        {
          type: 'DATE',
          label: '结束日期',
          fieldName: 'planEndDate',
          valueFormat: 'yyyy-MM-dd',
          disabled: true,
          initialValue: '',
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: '投放天数',
          fieldName: 'planTimeDay',
          initialValue: '',
          placeholder: '',
          disabled: true
        },
        { type: 'INPUT', label: '项目地点', fieldName: 'planProjectLocation', placeholder: '', initialValue: '', selfCols:1,disabled: true
        },
                          
        { type: 'INPUT', label: '展位计划金额', fieldName: 'planBoothAmount', placeholder: '单位（元）', initialValue: undefined,numberFormat:true
        },

        { type: 'INPUT_NUMBER', label: '目标集客数', fieldName: 'targetGuestsNum', placeholder: '数字', initialValue: undefined,
            disabled:true,
            precision:0,
            min:0,
            rules:[
            ],
            disabled: true
        },
          //无字段
        { type: 'INPUT', label: '搭建运营计划金额', fieldName: 'planBuildAmount', placeholder: '单位（元）', initialValue: undefined,numberFormat:true
        },
        { type: 'INPUT_NUMBER', label: '目标订单数', fieldName: 'targetOrderNum', placeholder: '数字', initialValue: undefined,
            disabled:true,
            precision:0,
            min:0,
            rules:[
            ],
            disabled: true
        },
        // { type: 'SELECT', label: '预算类别', fieldName: 'budgetType', placeholder: '请选择', initialValue: '', itemList: this.createDictList('8052'),
        //     rules: [
        //         {
        //         required: true,
        //         message: '必填',
        //         trigger: 'change'
        //         }
        //     ]
        // },
        
        { type: 'INPUT', label: '计划项目金额', fieldName: 'planProjectAmount', placeholder: '单位（元）', initialValue: undefined,numberFormat:true,
            disabled: true
        },
          { type: 'INPUT_NUMBER', label: '目标留档数', fieldName: 'targetRetentionNum', placeholder: '数字', initialValue: undefined,
            disabled:true,
            precision:0,
            min:0,
            rules:[
            ],
            disabled: true
        },
        
        
        { type: 'INPUT', label: '计划批准金额', fieldName: 'planApproveAmount', placeholder: '单位（元）', initialValue: undefined,   disabled:true,numberFormat:true,
        },
    
        {
          type: 'SELECT',
          label: '是否变更报备',
          fieldName: 'isChangePlan',
          initialValue: '',
          
          placeholder: '请选择...',
          itemList: this.createDictList('1004'),
          selfCols:2,
          change: this.isAllChange,
          rules: [{ required: true, message: '请选择是否需要变更报备', trigger: 'change' }]
        },
        {
          type: 'TEXT_AREA',
          label: '报备描述',
          fieldName: 'planDesc',
          initialValue: '',
          placeholder: '',
          selfCols:2,
          maxlength: 1000,
          rules: [{ required: false, message: '请填加报备描述', trigger: 'blur' }]
        },
        { type: 'UPLOAD_FILE', label: '附件', fieldName: 'uploadFileList', initialValue: [] ,selfCols:2,

            upload: {
                actionUrl: '/api/file/oss/upload', //上传的地址
                // tipText: '支持PDF/JPG/PNG/RAR格式，单个文件最大100M',
                limit:0,
                max:1024*100,
                fileTypes:['jpg',  'png', 'pdf', 'rar','ppt','pptx']
            }
        }
      ];
    },
    formChangeHandle(val) {
      this.formValue = val;
    },
    //取项目大类
    async initBigMarketType() {
      let res = [];
      let rd = await getBigMarketType();
      for (let i in rd.data) {
        if (rd.data[i].typeId == this.projectMainClass) {
          // this.initForm.find(item => item.fieldName === 'projectMainClass').initialValue = rd.data[i].typeName;
        }
        // res.push({ text: rd.data[i].typeName, value: rd.data[i].typeId });
      }
      // console.log(this.projectMainClass);
      // for (let i = 0; i < res.length; i++) {
      //   if (res[i].value == this.projectMainClass) {
      //     this.initForm.find(item => item.fieldName === 'projectMainClass').initialValue = res[i].text;
      //   }
      // }
    },
    async initMarketTypeSmall(parentTypeId) {
      let res = [];
      this.dataParams = { parentTypeId: parentTypeId };
      let rd = await getSmallMarketType(this.dataParams);
      for (let i in rd.data) {
        res.push({ text: rd.data[i].typeName, value: rd.data[i].typeId });
      }
      // this.initForm.find(item => item.fieldName === 'projectSmallClass').initialValue = res[0].text;
    }
  },
  created() {
    this.init();
  }
};
</script>
